//
//  WebController.m
//  Mayi
//
//  Created by 红沙尘 on 16/3/31.
//  Copyright © 2016年 红沙尘. All rights reserved.
//

#import "WebController.h"
#import "MJRefresh.h"

@interface WebController ()

@end

@implementation WebController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setTitle:@"支付"];
    
    myWebView.opaque = NO;
    myWebView.backgroundColor = [UIColor clearColor];
    myWebView.scrollView.backgroundColor = [UIColor whiteColor];

    
    myWebView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self refreshWebView];
    }];
    
    [myWebView.scrollView.mj_header beginRefreshing];
}

- (void)share
{

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)refreshWebView
{
    myWebView.scrollView.backgroundColor = [UIColor whiteColor];
    
    self.html_url = [self.html_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSURL *url = [NSURL URLWithString:self.html_url];
    [myWebView loadRequest:[NSURLRequest requestWithURL:url]];
}

#pragma mark - UIWebViewDelegate



- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//    NSString * html = [webView stringByEvaluatingJavaScriptFromString: @"document.documentElement.innerHTML"];
//    NSLog(@"html = %@",html);
//    
//    if ([html rangeOfString:@"<head></head>"].length > 0) {
//        NSString *head = @"<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><meta  charset=\"utf-8\"><meta  content=\"width=device-width,user-scalable=no,\" name=\"viewport\"></head>";
//        
//        html = [html stringByReplacingOccurrencesOfString:@"<head></head>" withString:head];
//        
//        [myWebView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://spdo.zjwee.cn/Plus/QrCode"]];
//    }
//    
    
    
    [myWebView.scrollView.mj_header endRefreshing];
    
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nonnull NSError *)error
{
    [myWebView.scrollView.mj_header endRefreshing];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}

@end
